<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <title>修改密码</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/config.js"></script>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#updatePwd").click(function () {
                updatePwd();
            })
        });
        function updatePwd() {
            var username=$("#username").val();
            var OldPassword=$("#OldPassword").val();
            var NewPssword=$("#NewPssword").val();
            var ReNewPssword=$("#ReNewPssword").val();
            if (username==""){alert("请输入用户名");return};
            if (OldPassword==""){alert("请输入旧密码");return};
            if (NewPssword==""){alert("请输入新密码");return};
            if (ReNewPssword==""){alert("请输入确认密码");return};
            if (NewPssword!=ReNewPssword){
                alert("两次输入密码不一致");
                return;
            }
            if (!checkPwd(NewPssword)){
                alert("密码只能输入6-20个字母、数字、下划线");
                return;
            }
            $("#updatePwd").text("正在修改...");
            var url="http://"+config.web_ip+"/Services/AndroidService.svc/Android/UpdateUserPwd?userName="+username+"&oldPwd="+OldPassword+"&newPwd="+NewPssword;
            $.post(url,function (data,state) {
                if(state){
                    if(data.Success){
                        alert("密码修改成功");
                        $.cookie("username","" , { expires: -1 });
                        $.cookie("password","" , { expires: -1 });
                        $.cookie("Id","" , { expires: -1 });
                        $.cookie("UserName","" , { expires: -1 });
                        window.location="http://"+config.local_ip+"/WebApp/Login.html";
                    }else{
                        alert(data.Msg);
                    }
                }else {
                    alert("请求服务器失败，请重试")
                }
                $("#updatePwd").text("确认修改");
            })
        }

        function checkPwd(s)
        {
            var patrn=/^(\w){6,20}$/;
            if (!patrn.exec(s)) return false;
            return true;
        }
    </script>
</head>
<body background="image/bg.png">
<img src="image/login_log.png" class="center-block img-responsive" style="margin-top: 15%">
    <div class="container" style="margin-top: 80px">
        <form>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                    <input type="text" class="form-control" id="username" style="height: 40px" placeholder="请输入用户名">
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                <input type="password" class="form-control" id="OldPassword" style="height: 40px" placeholder="请输入旧密码">
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                    <input type="password" class="form-control" id="NewPssword" style="height: 40px" placeholder="请输入新密码">
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                    <input type="password" class="form-control" id="ReNewPssword" style="height: 40px" placeholder="再次输入新密码">
                </div>
            </div>
            <button type="button" class="btn btn-default btn-block" style="height: 40px;margin-top: 50px" id="updatePwd">确认修改</button>
        </form>
    </div>
</body>
</html>